package com.itWaiLong.Utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Utils {
    public static String getMd5(String input){
        try{
            //实例MD5对象
            MessageDigest md = MessageDigest.getInstance("MD5");

            //计算哈希值
            byte[] digest = md.digest(input.getBytes());

            //将字节数组转为大整数
            BigInteger number = new BigInteger(1, digest);

            //将大整数转为十六进制数
            String hashtext = number.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        }catch (NoSuchAlgorithmException e){
            e.printStackTrace();
            return null;
        }
    }
}
